<!--该页面用于展示师傅的当周和下周的出诊安排-->
<template>
  <div class="out-box">
    <section >
      <div>
        <span class="title">本周出诊详情</span>
      </div>
      <div style="margin: 5px 0 -10px 0;">
        <span>{{sunday}}—{{saturday}}</span>
      </div>
      <div class="table-box">
        <table-list :tableAllData="tableAllData"></table-list>
      </div>
    </section>
  </div>

</template>

<script>
  import tableListNextWeek from '../../components/tableList'
  import {getVisitPlanList} from "@/api/doctor";
  import {getCookie} from "@/utils/cookies";
  import {tips} from "@/common/js/optionTips";
  import {numToWord, outCallTime} from "@/common/js/timeFilters";
  import {getWeek, dateForm} from "@/common/js/visitPlanData";
  import {getTreatRoomById} from "@/api/treatRoom";

  export default {
        name: "outCallDetail",
      components: {
        tableListNextWeek
      },
      data() {
        return {
          sunday: '',
          saturday: '',
          // 表格数据
          tableAllData: {
            dataNull: false,
            tableTitle: [{
              prop: 'ID',
              label: '编号',
              width: '180',
              option: ''
            }, {
              prop: 'date',
              label: '星期',
              width: '300',
              option: ''
            }, {
              prop: 'time',
              label: '时间段',
              width: '300',
              option: ''
            }, {
              prop: 'massage',
              label: '地址',
              width: '300',
              option: ''
            }],
            tableData: [],
            option: '',
            maxHeight: '100%'
          }
        }
      },
    methods: {
          // 通过师傅账号获取每周周师傅出诊计划
      getVisitPlanList: function (date, table) {
        table.tableData = [];
        let sunday = this.getDay("s",0);
        let saturday = this.getDay("e",0);
        this.sunday = sunday
        this.saturday = saturday
        console.log(sunday +'    '+ saturday)
        let that = this;
        getVisitPlanList(getCookie("username"), sunday, saturday).then(res => {
          console.log(res)
          if (res.code === 200) {
            let doctorList = res.data.doctorDTO;
            //let timePeriod = doctorList.duan.split(',');
            let date = doctorList.day.split(',');
            date.forEach(function (item,index){
              that.tableAllData.tableData.push({
                ID:index+1,
                date:'星期'+numToWord(item),
                time:doctorList.duan,
                massage:'万达店'
              })
            })
          }
        }).catch(() => {
          tips('error', "获取出诊计划失败")
        })
      },
      getDay(type, dates) {
         let now = new Date();
         console.log('            new',now)
         let nowTime = now.getTime();
        console.log('            newTime',nowTime)
         let day = now.getDay();
        console.log('            day',day)
         let longTime = 24 * 60 * 60 * 1000;
         let n = longTime * 7 * (dates || 0);
         let dd = ''
         if (type === "s") {
            dd = nowTime - (day - 1) * longTime + n;
         }
         if (type === "e") {
            dd = nowTime + (7 - day) * longTime + n;
         }
         dd = new Date(dd);
         let y = dd.getFullYear();
         let m = dd.getMonth() + 1;
         let d = dd.getDate();
         m = m < 10 ? "0" + m: m;
         d = d < 10 ? "0" + d: d;
         day = y + "-" + m + "-" + d;
         return day;
  }

  },
    created() {
      let that = this;
      let currentDate = new Date();
      let nextWeek = new Date();
      let date = currentDate.getDate();
      nextWeek.setDate(date + 7); // 下周对应的日期
      this.getVisitPlanList(currentDate, that.tableAllData); // 获取本周的出诊计划
    }
  }
</script>

<style scoped lang="scss">
  @import "../../common/scss/common";
  .out-box{
    @include width-margin(95%, auto);
    text-align: left;
    .title{
      height: 30px;
      @include font-style(16px, $major-blue-color);
    }
    .table-box{
      width: 100%;
      height: 100%;
    }
  }
  .next-box{
    margin-top: 30px;
  }
</style>
